class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int n=p.size();
        int has[26]={0};
        int cnt[26]={0};
        int left=0,right=0;
        vector<int> ret;
        for(int i=0;i<p.size();i++)
        {
            
            has[p[i]-'a']++;
        }

        cout<<endl;
        while(right<s.size())
        {
            cnt[s[right]-'a']++;
            while(left<=right && right-left+1>p.size())
            {
                cnt[s[left]-'a']--;
                left++;
            }
            if(right-left+1==p.size())
            {
                bool flg=true;
                for(int i=0;i<26 && flg;i++)
                {
                    flg=cnt[i]==has[i];
                
                }
                if(flg)
                    ret.push_back(left);
            }
            right++;
        }
        return ret;
    }
};
